#include "CSetVisibleCommand.h"
#include "CUserInterface.h"
#include "CLevelEditor.h"
#include "ISceneManager.h"
#include "ISceneNode.h"
#include "CGUITreeCtrl.h"

extern CGlobals* g;
extern CUserInterface* ui;
extern CLevelEditor* editor;

CSetVisibleCommand::CSetVisibleCommand (int id, bool setToVisible)
{
	m_id = id;
	m_setToVisible = setToVisible;
	setDescription(m_setToVisible ? L"make visible" : L"make invisible");
}

void CSetVisibleCommand::redo ()
{
	TreeNode* node = ui->m_sceneGraphTree->FindNode(m_id);
	node->Checked = m_setToVisible;
	node->SceneObject->m_SceneNode->setVisible(m_setToVisible);
	ui->setSceneNodeVisible(m_id,m_setToVisible);
	if (editor->getSelectedNode() == node->SceneObject->m_SceneNode && !m_setToVisible)
		editor->setSelectedNode(0);
}

void CSetVisibleCommand::undo ()
{
	TreeNode* node = ui->m_sceneGraphTree->FindNode(m_id);
	node->Checked = !m_setToVisible;
	node->SceneObject->m_SceneNode->setVisible(!m_setToVisible);
	ui->setSceneNodeVisible(m_id,!m_setToVisible);
	if (editor->getSelectedNode() == node->SceneObject->m_SceneNode && m_setToVisible)
		editor->setSelectedNode(0);
}
